package com.villaday.idf.fragment3;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import androidx.annotation.NonNull;
import androidx.core.widget.NestedScrollView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.appcompat.widget.LinearLayoutCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.villaday.idf.AppContext;
import com.villaday.idf.R;
import com.villaday.idf.activity.BackHandlerHelper;
import com.villaday.idf.activity.BieShuSearchResultActivity;
import com.villaday.idf.activity.BourbonListActivity;
import com.villaday.idf.activity.CashWithdrawalActivity;
import com.villaday.idf.activity.FragmentBackHandler;
import com.villaday.idf.activity.H5AutoTitleActivity;
import com.villaday.idf.activity.HomeBatchActivity;
import com.villaday.idf.activity.Home_temaiSearchActivity;
import com.villaday.idf.activity.HouseDetailsActivityFor3;
import com.villaday.idf.activity.InviteDownloadActivity;
import com.villaday.idf.activity.InviteLiBaoActivity;
import com.villaday.idf.activity.JDMSBSActivity;
import com.villaday.idf.activity.MinsuSearchResultActivity;
import com.villaday.idf.activity.MyOrderActivity;
import com.villaday.idf.activity.NotifyActivity;
import com.villaday.idf.activity.SVIPFreeActivity;
import com.villaday.idf.activity.SearchBournActivity;
import com.villaday.idf.activity.SearchMinSu2VActivity;
import com.villaday.idf.activity.WineShopDetailsActivity;
import com.villaday.idf.adapter3.HomeAreaAdapter;
import com.villaday.idf.adapter3.HomeCityAdapter;
import com.villaday.idf.adapter3.HomeExtraAdapter;
import com.villaday.idf.adapter3.HomeType3Adapter;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.BaseDialog;
import com.villaday.idf.base.BaseFragment;
import com.villaday.idf.base.BaseRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.custom.CustomBottomIv;
import com.villaday.idf.custom.CustomPopupWindow;
import com.villaday.idf.custom.DraggableFrameLayout;
import com.villaday.idf.custom.InvitedFriendDialog;
import com.villaday.idf.custom.LoadDialog;
import com.villaday.idf.custom.bannerUtil.BannerUtils;
import com.villaday.idf.custom.pop.SharePop;
import com.villaday.idf.model.MessageTypesEntity;
import com.villaday.idf.model.RefreshtokenEntity;
import com.villaday.idf.model.advertsCodeEntity;
import com.villaday.idf.model3.AllPostersEntity;
import com.villaday.idf.model3.ConfigsEntity;
import com.villaday.idf.model3.HomeDetailsEntity;
import com.villaday.idf.model3.PreSalesEntity;
import com.villaday.idf.util.Constant;
import com.villaday.idf.util.ImageViewUtils;
import com.villaday.idf.util.LogUtil;
import com.villaday.idf.util.NetworkUtil;
import com.villaday.idf.util.OkHttpUtil;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.ShareUtils;
import com.villaday.idf.util.SharedPreferencesUtil;
import com.villaday.idf.util.StatusBarUtil;
import com.villaday.idf.util.ToastUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import byc.imagewatcher.ImageWatcher;
import io.reactivex.functions.Consumer;
import me.bakumon.statuslayoutmanager.library.OnStatusChildClickListener;
import me.bakumon.statuslayoutmanager.library.StatusLayoutManager;

import static android.app.Activity.RESULT_OK;

public class Home3vFragment extends BaseFragment implements OnAdapterCallbackListener, OkHttpUtil.OnDataListener, FragmentBackHandler {


    @BindView(R.id.bus_home_top)
    BannerUtils busHomeTop;
    @BindView(R.id.iv_home_new_circle)
    ImageView ivHomeNewCircle;
    @BindView(R.id.rl_home_new)
    RelativeLayout rlHomeNew;
    @BindView(R.id.tv_home_hot)
    TextView tvHomeHot;


    @BindView(R.id.rv_home_city)
    RecyclerView rvHomeCity;
    @BindView(R.id.tv_home_extra)
    TextView tvHomeExtra;
    @BindView(R.id.tv_home_area)
    TextView tvHomeArea;
    @BindView(R.id.rv_home_extra)
    RecyclerView rvHomeExtra;
    @BindView(R.id.ll_home_area)
    LinearLayout llHomeArea;
    @BindView(R.id.rv_home_sale)
    RecyclerView rvHomeSale;
    @BindView(R.id.vw_home_bottom)
    View vwHomeBottom;
    @BindView(R.id.tv_home_sale_more)
    TextView tvHomeSaleMore;

    @BindView(R.id.nsv_home)
    NestedScrollView nsvHome;
    @BindView(R.id.srl_home)
    SwipeRefreshLayout srlHome;
    @BindView(R.id.tv_toolbar_home_area)
    TextView tvToolbarHomeArea;

    @BindView(R.id.rv_home_toolbar_extra)
    RecyclerView rvHomeToolbarExtra;

    @BindView(R.id.ll_toolbar_sale)
    LinearLayout llToolbarSale;
    @BindView(R.id.iv_home_toolbar_title)
    TextView ivHomeToolbarTitle;
    @BindView(R.id.iv_home_toolbar_new)
    ImageView ivHomeToolbarNew;
    @BindView(R.id.iv_home_toolbar_new_circle)
    ImageView ivHomeToolbarNewCircle;

    @BindView(R.id.tv_home_toolbar_new)
    TextView tvHomeToolbarNew;
    @BindView(R.id.ll_home_noBanner)
    LinearLayout llHomeNoBanner;
    @BindView(R.id.iv_home_qiu)
    ImageView ivHomeQiu;
    @BindView(R.id.dfl_home)
    DraggableFrameLayout dflHome;
    @BindView(R.id.rl_home)
    RelativeLayout rlHome;


    private ImageWatcher vImageWatcher;
    private AllPostersEntity.BodyBean allPostersEntity;
    private LoadDialog mLoadDialog;
    private int mPageNo = 1;
    private int mPageSize = 10;
    private int currentPagePosition = 0;//超值特卖
    private HomeDetailsEntity.BodyBean mBodyDetailsEntity;
    private HomeType3Adapter mHomeType3Adapter;
    private List<PreSalesEntity.BodyBean.ListBean> saleList = new ArrayList<>();


    //地址模块
    private HomeExtraAdapter mHomeExtraAdapter;
    private HomeCityAdapter mHomeCityAdapter;


    private int mHeight;//
    private List<HomeDetailsEntity.BodyBean.TopAdvertsBean> mTopAdverts;
    private Jump jump;
    private List<HomeDetailsEntity.BodyBean.DestinationsBean> mDestinations;
    private CustomPopupWindow mPopurArea;

    private List<ConfigsEntity.BodyBean.RegionsBean> mRegions;
    private List<ConfigsEntity.BodyBean.TagsBean> mTags;

    private HomeAreaAdapter mHomeAreaAdapter;
    private String mSid = "";
    private List<HomeDetailsEntity.BodyBean.PeopleNumberBean> mPeopleNumber;
    private boolean mIsLoadSale;
    private LinearLayoutManager mLinearLayoutManager;

    private int mSaleHeight;
    private boolean mIsScollY;
    private int mScrollY = 0;
    private boolean mIsBanner = false;//是否有Banner
    private boolean mIsHaveNew = false;//是否有新闻
    private advertsCodeEntity AEntity;
    private InvitedFriendDialog invitedFriendDialog;
    private boolean mIsReturnTop = false;
    private String cityName = "default";
    private String cityId = "default";
    private StatusLayoutManager statusLayoutManager;
    private Gson gson = new GsonBuilder().disableHtmlEscaping().create();
    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            try {
                if (msg.what == 1) {
                    getHomeNew();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };


    @Override
    protected int getViewResId() {
        return R.layout.fragment_home_3v;
    }


    public static Home3vFragment instance() {
        Home3vFragment home3vFragment = new Home3vFragment();
        return home3vFragment;
    }


    @Override
    protected void init(View v) {
        super.init(v);
        statusLayoutManager = setupDefaultStatusLayoutManager(rlHome, new OnStatusChildClickListener() {
            @Override
            public void onEmptyChildClick(View view) {
                //得到首页详细数据
                getHomeDetails();
                //得到消息数据
                getHomeNew();
                //得到邀请
                InviteFriend();
            }

            @Override
            public void onErrorChildClick(View view) {
                //得到首页详细数据
                getHomeDetails();
                //得到消息数据
                getHomeNew();
                //得到邀请
                InviteFriend();
            }

            @Override
            public void onCustomerChildClick(View view) {

            }
        });

        //初始化转发
        initSharePop();
        //初始化数据
        initFragment();
        //初始化Banner
        initBanner();
        //初始化列表
        initRecycle();
        //得到首页详细数据
        getHomeDetails();
        //得到消息数据
        getHomeNew();
        //得到邀请
        InviteFriend();

        getCity();
    }

    private void getCity() {
        Map<String, String> map = new HashMap<>();
        map.put("pageId", "00000");
        OkHttpUtil.getJSON(getActivity(), Constant.URL.configs, map, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                try {
                    LogUtil.jLog().e(json);
                    ConfigsEntity configsEntity = gson.fromJson(json, ConfigsEntity.class);
                    if (configsEntity.getCode().equals(Constant.Strings.SUC)) {
                        mRegions = configsEntity.getBody().getRegions();
                        mTags = configsEntity.getBody().getTags();
                        for (int i = 0; i < mTags.size(); i++) {
                            if (i == 0) {
                                mTags.get(i).setCheck(true);
                            } else {
                                mTags.get(i).setCheck(false);
                            }
                        }
                        mHomeExtraAdapter.setDatas(mTags);

                        //初始化 超值特卖
                        initSale();
                    }


                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void onFailure(String url, String error) {
            }
        });
    }


    private void getHomeNew() {
        OkHttpUtil.getJSON(getActivity(), Constant.URL.member_message_types, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                try {
                    LogUtil.jLog().e(json);
                    MessageTypesEntity messageTypesEntity = new Gson().fromJson(json, MessageTypesEntity.class);
                    if (messageTypesEntity.getCode().equals(Constant.Strings.SUC)
                            && messageTypesEntity.getBody() != null
                            && messageTypesEntity.getBody().size() != 0) {
                        List<MessageTypesEntity.BodyEntity> body = messageTypesEntity.getBody();
                        mIsHaveNew = false;
                        for (int i = 0; i < body.size(); i++) {
                            if (body.get(i).getBadge() != 0) {//有未读
                                mIsHaveNew = true;
                            }
                        }
                        if (mIsHaveNew) {
                            ivHomeNewCircle.setVisibility(View.VISIBLE);
                            ivHomeToolbarNewCircle.setVisibility(View.VISIBLE);
                        } else {
                            ivHomeNewCircle.setVisibility(View.GONE);
                            ivHomeToolbarNewCircle.setVisibility(View.GONE);
                        }
                    } else {
                        ivHomeNewCircle.setVisibility(View.GONE);
                        ivHomeToolbarNewCircle.setVisibility(View.GONE);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(String url, String error) {

            }
        });
    }

    /**
     * 首页详细数据
     */
    private void getHomeDetails() {
        OkHttpUtil.getJSON(getContext(), Constant.URL.home_configurations, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                try {
                    LogUtil.jLog().e(json);
                    if (statusLayoutManager != null) {
                        statusLayoutManager.showSuccessLayout();
                    }

                    if (srlHome != null && srlHome.isRefreshing()) {
                        srlHome.setRefreshing(false);
                    }

                    HomeDetailsEntity homeDetailsEntity = new Gson().fromJson(json, HomeDetailsEntity.class);
                    if ("200".equals(homeDetailsEntity.getCode())) {
                        mBodyDetailsEntity = homeDetailsEntity.getBody();
                        //Banner初始化
                        getBanner();
                        //初始化人数
                        if (mBodyDetailsEntity.getPeopleNumber() != null) {
                            mPeopleNumber = mBodyDetailsEntity.getPeopleNumber();
                            for (int i = 0; i < mPeopleNumber.size(); i++) {
                                if (mPeopleNumber.get(i).getId() == -1) {
                                    mPeopleNumber.get(i).setCheck(true);
                                } else {
                                    mPeopleNumber.get(i).setCheck(false);
                                }
                            }
                        }

                        //初始化城市
                        mDestinations = mBodyDetailsEntity.getDestinations();
                        mHomeCityAdapter.setData(mDestinations);


                        mSaleHeight = PhoneUtil.dp2px(getActivity(), 150) +
                                PhoneUtil.getHeight(tvHomeExtra) +
                                PhoneUtil.getHeight(tvHomeHot) +
                                PhoneUtil.getHeight(rvHomeCity);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(String url, String error) {
                if (statusLayoutManager != null && !NetworkUtil.isNetWorkAvilable(getContext())) {
                    statusLayoutManager.showErrorLayout();
                }
            }
        });
    }

    /**
     * 初始化上下Banner
     */
    private void getBanner() {
        if (mBodyDetailsEntity.getTopAdverts() != null && mBodyDetailsEntity.getTopAdverts().size() > 0) {
            llHomeNoBanner.setVisibility(View.GONE);
            rlHomeNew.setVisibility(View.VISIBLE);
            mIsBanner = true;
            mTopAdverts = mBodyDetailsEntity.getTopAdverts();
            List<String> urlString = new ArrayList<>();
            List<String> idString = new ArrayList<>();
            for (int i = 0; i < mTopAdverts.size(); i++) {
                urlString.add(mTopAdverts.get(i).getMaterial().getUrl());
                idString.add("空的");
            }
            busHomeTop.setData(R.layout.view_image, urlString, idString);
        } else {
            mIsBanner = false;
            rlHomeNew.setVisibility(View.GONE);
            llHomeNoBanner.setVisibility(View.VISIBLE);
        }

        busHomeTop.setDelegate(new BannerUtils.Delegate() {
            @Override
            public void onBannerItemClick(BannerUtils bannerUtils, View itemView, Object model, int position) {
                showDialog();
                LogUtil.jLog().e(new Gson().toJson(mTopAdverts.get(position)));
                setBannerSkip(mTopAdverts.get(position).getJumpType()
                        , mTopAdverts.get(position).getUrl()
                        , mTopAdverts.get(position).getMiniAppId()
                        , mTopAdverts.get(position).getMiniProgramType(), "");
            }
        });
    }

    /**
     * Banner跳转
     *
     * @param jumpType        跳转类型
     * @param urlString       外面的Url
     * @param miniAppId       小程序ID
     * @param miniProgramType 小程序Type
     */
    private void setBannerSkip(int jumpType, String urlString, String miniAppId, int miniProgramType, String name) {
        LogUtil.jLog().e(name + AppContext.currentCityidCurrent);
        switch (jumpType) {
            case 1://jumpType": "integer,跳转类型，1 APP页面跳转，
                if (urlString.contains("page/hotel/detail?id=")) {//id为酒店ID，如有其它参数原样带入查询
                    String[] split = urlString.split("=");
                    Intent intent1 = new Intent(getContext(), WineShopDetailsActivity.class);
                    intent1.putExtra("hotelId", split[1]);
                    startActivity(intent1);
                } else if (urlString.contains("page/house/detail?id=")) {//id为房源ID，如有其它参数原样带入查询
                    String[] split = urlString.split("=");
                    Intent intent1 = new Intent(getContext(), HouseDetailsActivityFor3.class);
                    intent1.putExtra("houseId", split[1]);
                    intent1.putExtra("persellId", split[1]);
                    startActivity(intent1);
                } else if (urlString.contains("page/village/detail?id=")) {//id为目的地ID，如有其它参数原样带入查询
                    //目的地详情页
                    String[] split = urlString.split("=");
                    Intent intent1 = new Intent(getContext(), BourbonListActivity.class);
                    intent1.putExtra("villageId", split[1]);
                    intent1.putExtra("city", "");
                    intent1.putExtra("area", "");
                    startActivity(intent1);
                } else if (urlString.contains("page/presell/detail?id=")) {//id为预售ID，如有其它参数原样带入查询
                    String[] split = urlString.split("=");
                    Intent intent1 = new Intent(getContext(), HouseDetailsActivityFor3.class);
                    intent1.putExtra("houseId", split[1]);
                    intent1.putExtra("persellId", split[1]);
                    intent1.putExtra("presellProduct", true);
                    startActivity(intent1);
                } else if (urlString.contains("page/village/list")) {//找房源-别墅
                    Intent intentBieShu = new Intent(getContext(), JDMSBSActivity.class);
                    intentBieShu.putExtra("type", 2);
                    if (!TextUtils.isEmpty(name)) {
                        cityName = AppContext.cityCurrent;
                        AppContext.cityCurrent = name;
                    }
                    if (urlString.split("=").length > 1) {
                        cityId = AppContext.currentCityidCurrent;
                        AppContext.currentCityidCurrent = urlString.split("=")[1].split("&")[0];
                    }
                    startActivityForResult(intentBieShu, Constant.Code.addressAddCode);
                } else if (urlString.contains("page/house/list")) {//找房源-民宿
                    Intent intentBieShu = new Intent(getContext(), JDMSBSActivity.class);
                    intentBieShu.putExtra("type", 1);
                    if (!TextUtils.isEmpty(name)) {
                        cityName = AppContext.cityCurrent;
                        AppContext.cityCurrent = name;
                    }
                    if (urlString.split("=").length > 1) {
                        cityId = AppContext.currentCityidCurrent;
                        AppContext.currentCityidCurrent = urlString.split("=")[1].split("&")[0];
                    }

                    startActivityForResult(intentBieShu, Constant.Code.addressAddCode);
                } else if (urlString.contains("page/hotel/list")) {//找房源-酒店
                    Intent intentBieShu = new Intent(getContext(), JDMSBSActivity.class);
                    intentBieShu.putExtra("type", 0);
                    if (!TextUtils.isEmpty(name)) {
                        cityName = AppContext.cityCurrent;
                        AppContext.cityCurrent = name;
                    }
                    if (urlString.split("=").length > 1) {
                        cityId = AppContext.currentCityidCurrent;
                        AppContext.currentCityidCurrent = urlString.split("=")[1].split("&")[0];
                    }
                    startActivityForResult(intentBieShu, Constant.Code.addressAddCode);
                } else if (urlString.contains("page/member")) {//我的
                    jump.homeJump(4, -1);
                } else if (urlString.contains("page/presell/search")) {//预售搜索
                    startActivity(new Intent(getContext(), Home_temaiSearchActivity.class));
                } else if (urlString.contains("page/home")) {//首页
                } else if ("page/search".equals(urlString)) {
                    //"page/search";  房源搜索索引页
                    Intent intent1 = new Intent(getContext(), SearchBournActivity.class);
                    intent1.putExtra("cityId", AppContext.currentCityidCurrent);
                    startActivity(intent1);
                } else if ("page/search/result".equals(urlString)) { //"page/search/result";  房源搜索结果页
                    Intent intent = new Intent(getContext(), BieShuSearchResultActivity.class);
                    intent.putExtra("isBieShu", true);
                } else if ("page/member/order".equals(urlString)) {
                    //"page/member/order";  我的订单
                    Intent intent1 = new Intent(getContext(), MyOrderActivity.class);
                    startActivity(intent1);
                } else if ("page/vip".equals(urlString)) {
                    if (jump != null) {
                        jump.homeJump(2, -1);
                    }
                } else if ("page/vip?show=1".equals(urlString)) {//跳vip页，弹出输入邀请码页
                    if (jump != null) {
                        jump.homeJump(2, -1);
                    }
                } else if ("page/vip/share".equals(urlString)) {
                    //"page/vip/share";  vip邀请好友分享页
                    if ("1".equals(SharedPreferencesUtil.getUserInfo(getContext()).getBody().getMember().getType())) {//vip
                        startActivity(new Intent(getContext(), InviteLiBaoActivity.class));
                    } else if ("2".equals(SharedPreferencesUtil.getUserInfo(getContext()).getBody().getMember().getType())) {//svip
                        startActivity(new Intent(getContext(), SVIPFreeActivity.class));
                    }
                } else if ("page/vip/draw".equals(urlString)) {
                    //"page/vip/draw";  vip提款页
                    startActivity(new Intent(getContext(), CashWithdrawalActivity.class));
                } else if ("page/search?type=1".equals(urlString)) {//民宿搜索页
                    Intent intent = new Intent(getContext(), SearchMinSu2VActivity.class);
                    startActivity(intent);
                } else if ("page/search/result?type=1".equals(urlString)) {//民宿搜索结果页
                    Intent intent = new Intent(getContext(), MinsuSearchResultActivity.class);
                    intent.putExtra("businessDistrictId", matchUrl(urlString, "businessDistrictId"));
                    intent.putExtra("tag", matchUrl(urlString, "tag"));
                    startActivity(intent);
                } else if ("page/vip/download".equals(urlString)) {//VIP邀请下载页
                    Intent intent = new Intent(getContext(), InviteDownloadActivity.class);
                    startActivity(intent);
                }
                break;
            case 2://2 内嵌页面链接跳转，
                Intent intent = new Intent(getContext(), H5AutoTitleActivity.class);
                intent.putExtra("title", "爱订房");
                intent.putExtra("url", urlString);
                startActivity(intent);
                break;
            case 3://3  跳转小程序",
                wxOpenApplet(miniAppId
                        , urlString
                        , miniProgramType);
                break;
            default:
                dismissDialogAndRefresh();
        }
    }


    public void onRefreshState() {
        StatusBarUtil.setTranslucentForImageViewInFragment(getActivity(), null);
        StatusBarUtil.setLightMode(getActivity());
    }


    /**
     * 初始化列表
     */

    @SuppressLint("ClickableViewAccessibility")
    private void initRecycle() {
        //城市
        rvHomeCity.setLayoutManager(new GridLayoutManager(getActivity(), 3));
        mHomeCityAdapter = new HomeCityAdapter(getActivity());
        mHomeCityAdapter.setOnItemClickListener(new AbsRecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                setBannerSkip(mDestinations.get(position).getJumpType()
                        , mDestinations.get(position).getUrl()
                        , mDestinations.get(position).getMiniAppId()
                        , mDestinations.get(position).getMiniProgramType()
                        , mDestinations.get(position).getName());
            }
        });
        rvHomeCity.setAdapter(mHomeCityAdapter);

        //特卖标签
        rvHomeExtra.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayout.HORIZONTAL, false));
        mHomeExtraAdapter = new HomeExtraAdapter(getActivity());
        mHomeExtraAdapter.setOnItemClickListener(new BaseRecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                if (mTags != null) {
                    for (int i = 0; i < mTags.size(); i++) {
                        if (i == position) {
                            mTags.get(i).setCheck(true);
                        } else {
                            mTags.get(i).setCheck(false);
                        }
                    }
                    mHomeExtraAdapter.notifyDataSetChanged();
                }
                //重新请求数据
                showDialog();
                mPageNo = 1;
                currentPagePosition = position;
                mIsReturnTop = false;
                initSale();
            }
        });
        rvHomeExtra.setAdapter(mHomeExtraAdapter);

        //顶部特卖特卖标签
        rvHomeToolbarExtra.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayout.HORIZONTAL, false));
        rvHomeToolbarExtra.setAdapter(mHomeExtraAdapter);


        mHomeType3Adapter = new HomeType3Adapter(getContext(), new OnAdapterCallbackListener() {
            @Override
            public void onCallback() {
            }
        }, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ////2 小区，3 房源 ，7 酒店，52 特卖(预售)
                ShareUtils.getData(Home3vFragment.this, (AppCompatActivity) getActivity(), "52", saleList.get((Integer) v.getTag()).getId());
            }
        });

        mLinearLayoutManager = new LinearLayoutManager(getContext());
        rvHomeSale.setLayoutManager(mLinearLayoutManager);
        rvHomeSale.setAdapter(mHomeType3Adapter);
        mHomeType3Adapter.setOnItemClickListener(new AbsRecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                Intent intent = new Intent(getContext(), HouseDetailsActivityFor3.class);
                intent.putExtra("type", 0);
                intent.putExtra("houseId", saleList.get(position).getId());
                intent.putExtra("presellProduct", true);
                intent.putExtra("brokerAge", saleList.get(position).getRebateAmount());
                intent.putExtra("persellId", saleList.get(position).getId());
                startActivity(intent);
            }
        });
        rvHomeSale.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (true || mLinearLayoutManager.findLastVisibleItemPosition() != 0) {
                    switch (newState) {
                        case RecyclerView.SCROLL_STATE_IDLE: //静止
                        case RecyclerView.SCROLL_STATE_SETTLING: //自动滚动
                            jump.homeJump(true);
                            break;
                    }
                }
            }
        });

        rvHomeSale.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_SCROLL:
                    case MotionEvent.ACTION_MOVE:
                    case MotionEvent.ACTION_DOWN:
                        dflHome.changeState(0.5);
                        break;
                    case MotionEvent.ACTION_UP:
                        if (!mIsScollY) {
                            dflHome.changeState(1);
                        }
                        break;
                }
                return false;
            }
        });
    }

    private void initSharePop() {
        mRxManager.on("sharepopEntity", new Consumer<AllPostersEntity.BodyBean>() {

            @Override
            public void accept(AllPostersEntity.BodyBean bodyBean) throws Exception {
                allPostersEntity = bodyBean;
            }
        });
        mRxManager.on("sharepop", new Consumer<ImageWatcher>() {
            @Override
            public void accept(ImageWatcher imageWatcher) throws Exception {
                vImageWatcher = imageWatcher;
                vImageWatcher.setImageWatcherOndismiss(new ImageWatcher.ImageWatcherDiss() {
                    @Override
                    public void onImageWatcherDiss() {
                        if (allPostersEntity != null) {
                            SharePop sharePop = new SharePop(Home3vFragment.this, getActivity(), getActivity(), allPostersEntity);
                            sharePop.showPopupWindow();
                        }
                    }
                });
            }
        });
    }

    @Override
    public boolean onBackPressed() {
        if (vImageWatcher == null) {
            return false;
        } else {
            // 当确认没有子Fragmnt时可以直接return false
            if (!vImageWatcher.handleBackPressed()) {
                return BackHandlerHelper.handleBackPress(this);
            } else {
                return !BackHandlerHelper.handleBackPress(this);
            }
        }
    }

    /**
     * 初始化超值特卖
     */
    private void initSale() {
        Map<String, String> map = new HashMap<>();
        map.put("pageNo", mPageNo + "");
        map.put("pageSize", mPageSize + "");
        map.put("tag", mTags.get(currentPagePosition).getValue());
        map.put("version", PhoneUtil.getAppVersion(getContext()));
        map.put("region", mSid);
        OkHttpUtil.getJSON(getContext(), Constant.URL.preSales, map, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                LogUtil.jLog().e(json);
                dismissDialogAndRefresh();
                PreSalesEntity preSalesEntity = new Gson().fromJson(json, PreSalesEntity.class);
                if ("200".equals(preSalesEntity.getCode()) && preSalesEntity.getBody().getList() != null && preSalesEntity.getBody().getList().size() != 0) {
                    rvHomeSale.setVisibility(View.VISIBLE);
                    tvHomeSaleMore.setVisibility(View.GONE);
                    if (mPageNo > 1 && mIsLoadSale) {//判定是否查询为加载
                        mIsLoadSale = false;
                        saleList.remove(saleList.size() - 1);

                        for (int i = 0; i < preSalesEntity.getBody().getList().size(); i++) {
                            preSalesEntity.getBody().getList().get(i).setMyType(0);
                            saleList.add(preSalesEntity.getBody().getList().get(i));
                        }

                        if (!preSalesEntity.getBody().isHasNext()) {
                            tvHomeSaleMore.setTextColor(getActivity().getResources().getColor(R.color.colorTextLight));
                            tvHomeSaleMore.setVisibility(View.VISIBLE);
                            tvHomeSaleMore.setText("没有更多了");
                        } else {
                            tvHomeSaleMore.setVisibility(View.GONE);
                            saleList.add(new PreSalesEntity.BodyBean.ListBean(1));
                        }
                    } else {
                        for (int i = 0; i < preSalesEntity.getBody().getList().size(); i++) {
                            preSalesEntity.getBody().getList().get(i).setMyType(0);
                        }
                        saleList = preSalesEntity.getBody().getList();

                        if (!preSalesEntity.getBody().isHasNext()) {
                            tvHomeSaleMore.setTextColor(getActivity().getResources().getColor(R.color.colorTextLight));
                            tvHomeSaleMore.setVisibility(View.VISIBLE);
                            tvHomeSaleMore.setText("没有更多了");
                        } else {
                            tvHomeSaleMore.setVisibility(View.GONE);
                            saleList.add(new PreSalesEntity.BodyBean.ListBean(1));
                        }
                    }
                    mHomeType3Adapter.setData(saleList);
                } else {
                    rvHomeSale.setVisibility(View.GONE);
                    tvHomeSaleMore.setVisibility(View.VISIBLE);
                    tvHomeSaleMore.setTextColor(getActivity().getResources().getColor(R.color.colorTextLight));
                    tvHomeSaleMore.setText("暂无数据");
                }


                if (mScrollY != 0 && mIsReturnTop) {
                    nsvHome.smoothScrollTo(0, mSaleHeight + 1);
                    mIsReturnTop = false;
                }
            }

            @Override
            public void onFailure(String url, String error) {

            }
        });

    }

    /**
     * 点击事件
     *
     * @param view
     */
    @OnClick({R.id.rl_home_new, R.id.tv_home_area, R.id.iv_home_area, R.id.tv_toolbar_home_area
            , R.id.iv_toolbar_home_area, R.id.tv_toolbar_label1, R.id.tv_toolbar_label2, R.id.tv_toolbar_label3
            , R.id.tv_toolbar_label4, R.id.ll_hint, R.id.iv_home_qiu, R.id.rl_home_toolbar_new
            , R.id.tv_home_toolbar_new, R.id.iv_home_toolbar_search, R.id.iv_home_search})
    public void btnOnclick(View view) {
        try {
            switch (view.getId()) {
                case R.id.iv_home_toolbar_search:
                case R.id.iv_home_search:
                    startActivity(new Intent(getContext(), Home_temaiSearchActivity.class));
                    break;
                case R.id.rl_home_new://消息
                case R.id.rl_home_toolbar_new:
                case R.id.tv_home_toolbar_new:
                    startActivityResult(NotifyActivity.class, Constant.Code.notifyAddCode);
//                    Intent intent1 = new Intent(getContext(), ShopActivity.class);
//                    intent1.putExtra("position", 0);
//                    startActivity(intent1);
                    break;
                case R.id.tv_toolbar_label3:
                    Intent intentMinSu = new Intent(getContext(), JDMSBSActivity.class);
                    intentMinSu.putExtra("type", 1);
                    getContext().startActivity(intentMinSu);
                    break;
                case R.id.tv_toolbar_label4:
                    Intent intentBieShu = new Intent(getContext(), JDMSBSActivity.class);
                    intentBieShu.putExtra("type", 2);
                    getContext().startActivity(intentBieShu);
                    break;
                case R.id.tv_home_area://选区域
                case R.id.iv_home_area:
                case R.id.iv_toolbar_home_area:
                case R.id.tv_toolbar_home_area:
                    initPopular(view);
                    break;
                case R.id.tv_toolbar_label2://酒店
                    Intent intentWineShop = new Intent(getContext(), JDMSBSActivity.class);
                    intentWineShop.putExtra("type", 0);
                    getContext().startActivity(intentWineShop);
                    break;
                case R.id.iv_home_qiu://悬浮球
                    startActivity(new Intent(getContext(), HomeBatchActivity.class));
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 初始化Popular
     *
     * @param view
     */
    public void initPopular(View view) {
        if (mPopurArea == null) {
            mPopurArea = new CustomPopupWindow.Builder().setheight(LinearLayoutCompat.LayoutParams.MATCH_PARENT)
                    .setwidth(LinearLayoutCompat.LayoutParams.MATCH_PARENT)
                    .setOutSideCancel(false)
                    .setContext(getContext())
                    .setActivity(getActivity())
                    .isBlur(true)
                    .setRadius(5)
                    .setContentView(R.layout.popu_bourn_head_chose_addr_sort)
                    .setOnDismissListener(new PopupWindow.OnDismissListener() {
                        @Override
                        public void onDismiss() {
                            mPopurArea = null;
                        }
                    })
                    .builder();
            mPopurArea.getItemView(R.id.close).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mPopurArea.dismiss();
                }
            });

            RecyclerView rvArea = (RecyclerView) mPopurArea.getItemView(R.id.rv_addr_sort);
            mHomeAreaAdapter = new HomeAreaAdapter(getActivity());
            rvArea.setLayoutManager(new LinearLayoutManager(getContext()));
            rvArea.setAdapter(mHomeAreaAdapter);
            mHomeAreaAdapter.setOnItemClickListener(new AbsRecyclerViewAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View v, int position) {
                    try {

                        boolean isCheck = false;
                        for (int i = 0; i < mRegions.size(); i++) {
                            if (i == position) {
                                if (mRegions.get(i).isCheck()){
                                    isCheck = true;
                                    mRegions.get(0).setCheck(true);
                                    mRegions.get(i).setCheck(false);
                                }else {
                                    mRegions.get(i).setCheck(true);
                                }
                            } else {
                                mRegions.get(i).setCheck(false);
                            }
                        }

                        if (isCheck){
                            tvHomeArea.setText("选城市");
                            tvToolbarHomeArea.setText("选城市");
                            mSid = mRegions.get(0).getValue();
                        }else {
                            tvHomeArea.setText(mRegions.get(position).getName());
                            tvToolbarHomeArea.setText(mRegions.get(position).getName());
                            //查询地区
                            mSid = mRegions.get(position).getValue();
                        }
                        mHomeAreaAdapter.setData(mRegions);
                        mPageNo = 1;
                        showDialog();
                        mIsReturnTop = true;
                        initSale();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                    mPopurArea.dismiss();
                }
            });
            mHomeAreaAdapter.setData(mRegions);
            if (view.getId() == R.id.tv_toolbar_home_area || view.getId() == R.id.iv_toolbar_home_area) {
                mPopurArea.showAsLaction(llToolbarSale, Gravity.BOTTOM, 0, 0);
            } else {
                mPopurArea.showAsLaction(llHomeArea, Gravity.BOTTOM, 0, 0);
            }

        } else {
            mPopurArea.dismiss();
        }
    }


    /**
     * 初始化数据
     */
    @SuppressLint("ClickableViewAccessibility")
    private void initFragment() {
        try {
            showDialog();
            StatusBarUtil.setTranslucentForImageViewInFragment(getActivity(), null);
            StatusBarUtil.setLightMode(getActivity());


            //是否是Vip
            RefreshtokenEntity.BodyBean roleInfo = SharedPreferencesUtil.getRoleInfo(getContext());
            LogUtil.jLog().e(new Gson().toJson(roleInfo));
            if (roleInfo != null && !roleInfo.getMember().getType().equals("0")) {
                ivHomeQiu.setVisibility(View.VISIBLE);
                Glide.with(this).asGif().load(R.drawable.ic_gif).into(ivHomeQiu);
            } else {
                ivHomeQiu.setVisibility(View.GONE);
            }


            //初始化刷新
            srlHome.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
                @Override
                public void onRefresh() {
                    getHomeDetails();
                }
            });
            //渐变效果
            ScrollY();


            nsvHome.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    switch (event.getAction()) {
                        case MotionEvent.ACTION_SCROLL:
                        case MotionEvent.ACTION_MOVE:
                        case MotionEvent.ACTION_DOWN:
                            dflHome.changeState(0.5);
                            break;
                        case MotionEvent.ACTION_UP:
                            if (!mIsScollY) {
                                dflHome.changeState(1);
                            }
                            break;
                    }
                    return false;
                }
            });
            mHeight = PhoneUtil.dp2px(getActivity(), 30);
            nsvHome.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {

                @Override
                public void onScrollChange(NestedScrollView nestedScrollView, int i, int i1, int i2, int oldy) {
                    mScrollY = i1;

                    mOnScrollHomeListener.onScroll(i1, mHeight);
                    //判定批量转发移动
                    if (Math.abs(i1 - oldy) > 2 && !PhoneUtil.isVisible(getActivity(), tvHomeSaleMore) && i1 != 0) {
                        mIsScollY = true;
                        dflHome.changeState(0.5);
                    } else {
                        mIsScollY = false;
                        dflHome.changeState(1);
                    }

                    ScrollY();

                    //判定吸顶
                    if (i1 >= mSaleHeight) {
                        llToolbarSale.setVisibility(View.VISIBLE);
                        llHomeNoBanner.setVisibility(View.GONE);
                    } else {
                        llToolbarSale.setVisibility(View.GONE);
                    }


                    if (PhoneUtil.isVisible(getActivity(), vwHomeBottom) && !mIsLoadSale && tvHomeSaleMore.getVisibility() != View.VISIBLE) {
                        mPageNo++;
                        initSale();
                        mIsLoadSale = true;//是否加载
                    }
                }
            });
            new Thread() {
                public void run() {
                    try {
                        handler.postDelayed(this, 30000);
                        Message msg = new Message();
                        msg.what = 1;
                        if (handler != null) {
                            handler.sendMessage(msg);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }.start();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    private void ScrollY() {
        if (mScrollY <= mHeight) {
            //设置标题的背景颜色
            if (!mIsBanner) {
                llHomeNoBanner.setVisibility(View.VISIBLE);
                ivHomeToolbarTitle.setTextColor(Color.argb(255, 50, 50, 50));
                tvHomeToolbarNew.setTextColor(Color.argb(255, 50, 50, 50));
                ImageViewUtils.setImageViewColor(ivHomeToolbarNew, Color.argb(255, 51, 51, 51));
                ImageViewUtils.setImageViewColor(ivHomeToolbarNewCircle, Color.argb(255, 247, 54, 55));
            }
        } else if (mScrollY > mHeight && mScrollY <= mHeight + PhoneUtil.dp2px(getContext(), 40)) {
            // 滑动距离小于图的高度时，设置背景和字体颜色颜色透明度渐变
            float scale = (float) (mScrollY - mHeight) / PhoneUtil.dp2px(getContext(), 40);
            float alpha = (255 * scale);

            if (!mIsBanner) {//没Banner
                llHomeNoBanner.setVisibility(View.VISIBLE);
                ivHomeToolbarTitle.setTextColor(Color.argb(255 - (int) alpha, 50, 50, 50));
                tvHomeToolbarNew.setTextColor(Color.argb(255 - (int) alpha, 50, 50, 50));
                ImageViewUtils.setImageViewColor(ivHomeToolbarNew, ImageViewUtils.blendColors(Color.argb(255, 51, 51, 51), Color.argb(0, 51, 51, 51), scale));
                ImageViewUtils.setImageViewColor(ivHomeToolbarNewCircle, ImageViewUtils.blendColors(Color.argb(255, 247, 54, 55), Color.argb(0, 247, 54, 55), scale));
            }
        } else if (mScrollY <= mSaleHeight) {
            if (!mIsBanner) {
                llHomeNoBanner.setVisibility(View.GONE);
            }
        }
    }

    /**
     * 停止加载框
     */
    protected void dismissDialogAndRefresh() {
        if (mLoadDialog != null) {
            mLoadDialog.dismiss();//获取信息后关闭对话框
        }
        if (srlHome != null && srlHome.isRefreshing()) {
            srlHome.setRefreshing(false);
        }
    }

    /**
     * 设置加载框
     */
    protected void showDialog() {
        if (mLoadDialog == null) {
            mLoadDialog = LoadDialog.newInstance("加载中");
        }
        mLoadDialog.show(getActivity().getSupportFragmentManager(), "loading");
    }


    /**
     * 初始化Banner
     */
    private void initBanner() {
        //Banner适配
        busHomeTop.setAdapter(new BannerUtils.Adapter() {
            @Override
            public void fillBannerItem(BannerUtils bannerUtils, View itemView, Object model, int position) {
                RequestOptions options = new RequestOptions()
                        .error(R.drawable.ic_home_bg)
                        .dontAnimate()
                        .placeholder(R.drawable.ic_home_bg);
                Glide.with(itemView.getContext())
                        .load(model)
                        .apply(options)
                        .into((CustomBottomIv) itemView);
            }
        });
    }


    /**
     * 跳转到顶部
     */
    public void setSkip(int position) {
        nsvHome.smoothScrollTo(0, position);
    }

    private onScrollHomeListener mOnScrollHomeListener;

    public void setOnScrollWineListener(onScrollHomeListener onScrollWineListener) {
        this.mOnScrollHomeListener = onScrollWineListener;
    }

    @Override
    public void onCallback() {

    }


    public interface onScrollHomeListener {
        void onScroll(int scrollY, int height);
    }

    public void setOnJumpListener(Jump jump) {
        this.jump = jump;
    }

    @Override
    public void onResume() {
        super.onResume();
        dismissDialogAndRefresh();
    }

    public interface Jump {
        void homeJump(int jumpType, int innerJumpType);

        void homeJump(boolean isOk);
    }


    /**
     * APP打开小程序
     */
    public void wxOpenApplet(String userName, String path, int miniProgramType) {
        IWXAPI api = WXAPIFactory.createWXAPI(getContext(), Constant.ID.WeChat_APP_ID);
        if (!api.isWXAppInstalled()) {//未安装微信
            ToastUtil.initToast(getContext(), "您未安装微信");
            return;
        }
        WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
        req.userName = userName; // 填小程序原始id
        req.path = path;                  //拉起小程序页面的可带参路径，不填默认拉起小程序首页
        //      "miniProgramType": "integer,小程序版本，1：开发版 2：预览版 3：正式版，jumpType为3时必然存在"
        if (miniProgramType == 1) {
            req.miniprogramType = WXLaunchMiniProgram.Req.MINIPROGRAM_TYPE_TEST;// 可选打开 开发版，体验版和正式版

        } else if (miniProgramType == 2) {
            req.miniprogramType = WXLaunchMiniProgram.Req.MINIPROGRAM_TYPE_PREVIEW;// 可选打开 开发版，体验版和正式版

        } else if (miniProgramType == 3) {
            req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;// 可选打开 开发版，体验版和正式版

        }
        api.sendReq(req);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == 123) {//城市搜索
                AppContext.currentCityidCurrent = data.getStringExtra("cityId");//当前城市id
                AppContext.cityCurrent = data.getStringExtra("cityName");//当前城市id
                if (!mIsReturnTop) {
                    showDialog();
                }

                mPageNo = 1;
                currentPagePosition = 0;
                mIsReturnTop = true;
                initSale();
            }
        }
        if (requestCode == Constant.Code.notifyAddCode) {
            //得到消息数据
            getHomeNew();
        }

        if (requestCode == Constant.Code.addressAddCode) {
//            LogUtil.jLog().e(cityName + "   " + cityId);
            AppContext.cityCurrent = cityName;
            AppContext.currentCityidCurrent = cityId;
        }
    }

    /**
     * time 201904115
     */
    private void InviteFriend() {
        /**
         * 弹出好友邀请框根据有效期来判断
         * 如果默认返回"0",说明首次弹出邀请好友对话框
         * 2.如果不是首次，则获取上次保存的时间是否超过有效期，超过再次请求显示
         * 否则不显示
         */
        if (SharedPreferencesUtil.getLastHome2vAdvertTime(getActivity()).equals("0")) {
            OkHttpUtil.getJSON(getContext(), Constant.URL.adverts + "170002", this);
            Log.e("adverts", "----" + SharedPreferencesUtil.getLastHome2vAdvertTime(getActivity()));
        } else {
            long mills = Long.parseLong(SharedPreferencesUtil.getLastHome2vAdvertTime(getActivity()));
            Log.e("adverts", "mills=" + mills + " System.currentTimeMillis=" + System.currentTimeMillis());
            if (System.currentTimeMillis() > mills) {
                OkHttpUtil.getJSON(getContext(), Constant.URL.adverts + "170002", this);
            }
        }
    }


    @Override
    public void onResponse(String url, String json) {
        try {
            LogUtil.jLog().e(json);
            AEntity = new Gson().fromJson(json, advertsCodeEntity.class);
            if ("200".equals(AEntity.getCode())) {
                //保存当前时间+有效时间
                SharedPreferencesUtil.saveLastHome2vAdvertTime(getActivity(), (System.currentTimeMillis() + AEntity.getBody().get(0).getPeriodTime() * 1000) + "");
                //弹出邀请好友框
                invitedFriendDialog = InvitedFriendDialog.newInstance(getActivity(), AEntity.getBody().get(0).getMaterial().getUrl());
                invitedFriendDialog.setOnItemClickListener(new BaseDialog.OnItemClickListener() {
                    @Override
                    public void onItemClick(View v) {
                        try {
                            advertsCodeEntity.BodyBean bodyBean = AEntity.getBody().get(0);
                            setBannerSkip(bodyBean.getJumpType(), bodyBean.getUrl(), bodyBean.getMiniAppId(), bodyBean.getMiniProgramType(), "");
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
                invitedFriendDialog.show(getActivity().getFragmentManager());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private String matchUrl(String url, String parm) {
        if (url.contains("?")) {
            String parentValue = url.split("\\?")[1];
            if (parentValue.contains(parm)) {
                if (parentValue.contains("&")) {
                    String[] childValue = parentValue.split("&");
                    for (int i = 0; i < childValue.length; i++) {
                        if (childValue[i].contains(parm)) {
                            return childValue[i].split("=")[1];
                        }
                    }
                } else {
                    return parentValue.split("=")[1];
                }
            } else {
                return "";
            }
        } else {
            return "";
        }
        return "";
    }

    @Override
    public void onFailure(String url, String error) {

    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        if (handler != null) {
            handler.removeCallbacksAndMessages(null);
            handler = null;
        }
    }
}
